import { requestClient } from '#/api/request';

export namespace MachineryApi {
  export type Params = object;
  export interface GetMachineryReq {
    pageNum: number;
    pageSize: number;
    planId?: number;
  }

  export interface Row {
    searchValue: null;
    createBy: string;
    createTime: Date;
    updateBy: string;
    updateTime: Date | null;
    remark: string;
    params: Params;
    machineryId: number;
    machineryCode: string;
    machineryName: string;
    machineryBrand: null | string;
    machinerySpec: null | string;
    machineryTypeId: number;
    machineryTypeCode: null;
    machineryTypeName: null | string;
    workshopId: number;
    workshopCode: null | string;
    workshopName: null | string;
    status: string;
    attr1: null | string;
    attr2: null;
    attr3: number;
    attr4: number;
  }

  export interface GetMachineryListResp {
    total: number;
    rows: Row[];
    code: number;
    msg: string;
  }

  export interface CheckRow {
    searchValue: null;
    createBy: string;
    createTime: Date;
    updateBy: string;
    updateTime: Date | null;
    remark: string;
    params: Params;
    recordId: number;
    planId: number;
    machineryId: number;
    machineryCode: string;
    machineryName: string;
    machineryBrand: string;
    machinerySpec: string;
    attr1: null | string;
    attr2: null;
    attr3: number;
    attr4: number;
  }

  export interface GetCheckMachineryListResp {
    total: number;
    rows: CheckRow[];
    code: number;
    msg: string;
  }
}

// 获取类型列表
export const getMachineryList = (params: MachineryApi.GetMachineryReq) =>
  requestClient.get<MachineryApi.GetMachineryListResp>(
    '/mes/dv/machinery/list',
    {
      params,
    },
  );

// 修改保养项目设置
export const updateMachinery = (data: MachineryApi.Row) =>
  requestClient.put<MachineryApi.GetMachineryListResp>(
    '/mes/dv/machinery',
    data,
  );

// 增加保养项目设置
export const addMachinery = (data: MachineryApi.Row) =>
  requestClient.post<MachineryApi.GetMachineryListResp>(
    '/mes/dv/machinery',
    data,
  );

// 删除保养项目设置
export const deleteMachinery = (id: string) =>
  requestClient.delete<MachineryApi.GetMachineryListResp>(
    `/mes/dv/machinery/${id}`,
  );

export const getCheckMachineryList = (params: MachineryApi.GetMachineryReq) =>
  requestClient.get<MachineryApi.GetCheckMachineryListResp>(
    '/mes/dv/checkmachinery/list',
    {
      params,
    },
  );

// 修改Tabs 保养项目设置
export const updateCheckMachinery = (data: MachineryApi.CheckRow) =>
  requestClient.put<MachineryApi.GetCheckMachineryListResp>(
    '/mes/dv/checkmachinery',
    data,
  );

// 增加Tabs 保养项目设置
export const addCheckMachinery = (data: MachineryApi.CheckRow) =>
  requestClient.post<MachineryApi.GetCheckMachineryListResp>(
    '/mes/dv/checkmachinery',
    data,
  );

// 删除Tabs 保养项目设置
export const deleteCheckMachinery = (id: string) =>
  requestClient.delete<MachineryApi.GetCheckMachineryListResp>(
    `/mes/dv/checkmachinery/${id}`,
  );
